<!DOCTYPE html>
<html>
	{include file="head.html"}
	<body>
		<div class="tabs-border">
			<div>{$table.title}:{$table.tablename}</div>
			<a href="?m=table_data&tableid={$table.tableid}" class="item">数据列表</a>
			
			<a href="?m=table_data&a=add&tableid={$table.tableid}" class="item active">发布</a>
			<a href="?m=table_fields&a=table&tableid={$table.tableid}" class="item">表设计</a>
		</div>
		<div class="main-body">
			<form  class="list">
				<input type="hidden" name="id" value="{$data.id}" />
				<input type="hidden" name="tableid" value="{$table.tableid}" />
				{foreach item=c from=$fieldsList}
				{if $c.fieldtype eq 'text'}
				<div class="input-flex">
					<div class="input-flex-label">{$c.title}</div>
					<input type="text" name="tablefield[{$c.fieldname}]" value="{$c.value}" />
				</div>
				{elseif $c.fieldtype eq 'textarea'}
				<div class="textarea-flex">
					<div class="textarea-flex-label">{$c.title}</div>
					<textarea name="tablefield[{$c.fieldname}]" class="textarea-flex-text h60">{$c.value}</textarea>
				</div>
				{elseif $c.fieldtype eq 'select'}
				<div class="input-flex">
					<div class="input-flex-label">{$c.title}</div>
					<select name="tablefield[{$c.fieldname}]">
						<option value="">请选择</option>
						{foreach item=ss from=$c.opsList}
						<option value="{$ss}" {if $ss eq $c.value}selected{/if}>{$ss}</option>
						{/foreach}
					</select>	
				</div>
				{elseif $c.fieldtype eq 'html'}
				<div class="textarea-flex">
					<div class="textarea-flex-label">{$c.title}</div>
					<div class="js-html-item">
						<textarea name="tablefield[{$c.fieldname}]" class="none js-html-textarea">{$c.value}</textarea>
						<div contenteditable="true" class="sky-editor-content textarea-flex-text ">{$c.value}</div>
					</div>
				</div>
				{elseif $c.fieldtype eq 'img'}
				<div class="input-flex">
					<div class="input-flex-label">{$c.title}</div>
					<div class="flex-1">
						<div class="js-upload-item">
							<input type="file" id="tablefield{$c.id}" class="js-upload-file" style="display: none;" />
							<div class="upimg-btn js-upload-btn">+</div>
							<input type="hidden" name="tablefield[{$c.fieldname}]" class="js-imgurl" value="{$c.value}" />
							<div class="js-imgbox">
								{if $c.value}
								<img src="{$c.value|images_site}.100x100.jpg" class="w60" />
								{/if}
							</div>
						</div>
					</div>
				</div>
				{elseif $c.fieldtype eq 'map'}
				<div class="input-flex">
					<div class="input-flex-label">地图</div>
					<div class="flex-1  js-map">
						<input type="hidden" class="map-value"  name="tablefield[{$c.fieldname}]"  value="{$c.value}" />
						<div class="flex">
							<input type="text" id="mapWord" />
							<div id="mapSearch" class="input-flex-btn">搜一下</div>
						</div>
						<div class="map" id="map" style="width: 400px; height: 300px;"></div>
					</div>
				</div>	
				
				{/if}
				{/foreach}
				<div class="btn-row-submit" id="submit">保存</div>
				
			</form>
		</div>
		{include file="footer.html"}
		<script language="javascript" src="/static/admin/js/upload.js"></script>
		<script src="/plugin/lrz/lrz.bundle.js"></script>
		<script src="/plugin/skyeditor/skyeditor.js"></script>
		<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak={const.BDMAPKEY}"></script>
		<script>
			var maps=$(".js-map");
			var $field=maps.find(".map-value");
			 var map = new BMap.Map("map");
			 map.enableScrollWheelZoom();
			  // 添加带有定位的导航控件
			  var navigationControl = new BMap.NavigationControl({
				// 靠左上角位置
				anchor: BMAP_ANCHOR_TOP_LEFT,
				// LARGE类型
				type: BMAP_NAVIGATION_CONTROL_LARGE,
				// 启用显示定位
				enableGeolocation: true
			  });
			  map.addControl(navigationControl);
			  var geolocationControl = new BMap.GeolocationControl();
			  map.addControl(geolocationControl);
			 var point = new BMap.Point(118.165810,24.485228);
			  map.centerAndZoom(point, 12);
			  var marker = new BMap.Marker(point);  // 创建标注
			 map.addOverlay(marker); 
			 map.addEventListener("click", function(e){
			   map.removeOverlay(marker);
			   point = new BMap.Point(e.point.lng,e.point.lat);
			   marker = new BMap.Marker(point);  // 创建标注
			   
			 		map.addOverlay(marker);  
			   $field.val(e.point.lng+","+e.point.lat);
			   
			 });
			  function localsearch(word){
			   var local = new BMap.LocalSearch(map, {
			 		  renderOptions:{map: map}
			 		});
			 		local.search(word);
			 }
			 var lastword="";
			 $(document).on("click","#mapSearch",function(){
				 var word=$("#mapWord").val();
				 if(word==lastword){
					 return false;
				 }
				 lastword=word;
				 if(word==""){
					 map.centerAndZoom(point, 12);
				 }else{
					 
					 localsearch(word) 
				 }
				
			 })
		</script>
		<script>
			$(document).on("click","#submit",function(){
				var form=$(this).parents("form");
				var len=$(".sky-editor-content").length;
				for(var i=0;i<len;i++){
					var $e=$(".sky-editor-content:eq("+i+")");
					$e.parents(".js-html-item").find(".js-html-textarea").val($e.html());
				}
				$.ajax({
					url:"?m=table_data&a=save&ajax=1",
					data:form.serialize(),
					method:"POST",
					success:function(res){
						goBack();
					}
				})
			})
		</script>
	</body>
</html>
